/******************************************************************************
* File description: experimentopenfileui.cpp
* Function: 实验-打开文件
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-31
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
#include "experimentopenfileui.h"

#include <QSysInfo>

ExperimentOpenFileUI::ExperimentOpenFileUI() {
    // 初始化
    this->setResizeMode(QQuickWidget::SizeRootObjectToView);
    this->setSource(QUrl("qrc:/experimentopenfile.qml"));

    this->locateFileUI = new OpenFileLocateFileUploadUI();
    this->locateFileUI->setParent(this, Qt::Dialog | Qt::WindowCloseButtonHint);


    connect(locateFileUI, &OpenFileLocateFileUploadUI::cancel, this, [=](){
        // QWidget::update();
        // this->update();
        // locateFileUI->close();
        this->update();
        QQuickWidget::update();
        emit ExperimentOpenFileUI::cancel();
    });
    // this->locateFileUI->setAttribute(Qt::WA_DeleteOnClose);

    this->othersFileUI = new OpenFileOthersFileUploadUI();
    this->othersFileUI->setParent(this, Qt::Dialog | Qt::WindowCloseButtonHint);

    rootObj = this->getRootObject();
    if(rootObj){
        connect(rootObj, SIGNAL(uploadLocateFile()), this, SLOT(onUploadLocateFile()));
        connect(rootObj, SIGNAL(uploadOthersFile()), this, SLOT(onUploadOthersFile()));
        connect(rootObj, SIGNAL(returnSig()), this, SIGNAL(returnSig()));
    }
}

ExperimentOpenFileUI::~ExperimentOpenFileUI() {}

/**
 * @brief getContext 获取qmlcontext
 * @return qmlContext
 */
QQmlContext* ExperimentOpenFileUI::getContext() const
{
    return this->rootContext();
}

/**
 * @brief getRootObject 获取rootObject
 * @return rootObject
 */
QObject* ExperimentOpenFileUI::getRootObject() const
{
    return (QObject*)this->rootObject();
}

void ExperimentOpenFileUI::onUploadLocateFile()
{
    this->locateFileUI->move((this->width() - this->locateFileUI->width()) / 2,
                             (this->height() - this->locateFileUI->height()) / 2);
    this->locateFileUI->show();
}

void ExperimentOpenFileUI::onUploadOthersFile()
{
    this->othersFileUI->show();
}

